package com.microstream.user;

import java.util.List;

import javax.jdo.PersistenceManager;
import javax.servlet.http.HttpSession;

import com.microstream.global.GlobalConstant;
import com.microstream.dao.*;

public class UserUtility {

	public static String getLoginUserFromSession(HttpSession session)
	{
		if( session == null ) 
			return "";
		else
		{	
			if(session.getAttribute(GlobalConstant.SESSION_USER_LOGIN_NAME)== null) {
				return ""; 
			}
			return session.getAttribute(GlobalConstant.SESSION_USER_LOGIN_NAME).toString();
		}		
	}
	
	public static MsUser getOneUser(PersistenceManager pm,String userName) {		 
	    String query = "select from " + MsUser.class.getName() 
	                 + " where userName == '" + userName + "'";
	    List<MsUser> users = (List<MsUser>) pm.newQuery(query).execute();
	    
	    if(users.size() >= 1) {
	      MsUser user = users.get(0);
	      return user; 
	    }	    
	    	   	   
		return null; 		
	}
	
	
}
